package cn.iocoder.yudao.module.pay.service.order;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.pay.controller.admin.order.vo.HuifuOrderPageReqVO;
import cn.iocoder.yudao.module.pay.controller.admin.order.vo.HuifuOrderSaveReqVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.order.HuifuOrderDO;
import cn.iocoder.yudao.module.pay.dal.mysql.order.HuifuOrderMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;


/**
 * 汇付对帐订单 Service 实现类
 *
 * @author 万商汇
 */
@Service
@Validated
public class HuifuOrderServiceImpl implements HuifuOrderService {

    @Resource
    private HuifuOrderMapper orderMapper;

    @Override
    public Integer createOrder(HuifuOrderSaveReqVO createReqVO) {
        // 插入
        HuifuOrderDO order = BeanUtils.toBean(createReqVO, HuifuOrderDO.class);
        orderMapper.insert(order);
        // 返回
        return order.getId();
    }

    @Override
    public void updateOrder(HuifuOrderSaveReqVO updateReqVO) {
        // 校验存在
        validateOrderExists(updateReqVO.getId());
        // 更新
        HuifuOrderDO updateObj = BeanUtils.toBean(updateReqVO, HuifuOrderDO.class);
        orderMapper.updateById(updateObj);
    }

    @Override
    public void deleteOrder(Integer id) {
        // 校验存在
        validateOrderExists(id);
        // 删除
        orderMapper.deleteById(id);
    }

    private void validateOrderExists(Integer id) {
        if (orderMapper.selectById(id) == null) {
            return;
        }
    }

    @Override
    public HuifuOrderDO getOrder(Integer id) {
        return orderMapper.selectById(id);
    }

    @Override
    public PageResult<HuifuOrderDO> getOrderPage(HuifuOrderPageReqVO pageReqVO) {
        return orderMapper.selectPage(pageReqVO);
    }

}